---
title: "Analysis of Open-Ended Survey Responses (Experiment 2)"
output:
  pdf_document: default
  html_document: default
date: "2025-10-06"
---

## Packages used:

```{r, echo = T, results = 'hide', error=FALSE, warning=FALSE, message=FALSE}
rm(list = ls())
library(tidyverse)
library(ggplot2)
library(ggrepel)
library(ggpubr)
library(estimatr)
library(dotwhisker)
library(broom)
library(dplyr)
library(sjPlot)
library(hrbrthemes)
library(ivreg)
library(readxl)
library(gtools)
library(stargazer)
library(cobalt)
library(summarytools)
library(pwrss)
library(pwr)
```

## Importing Data. 

```{r,echo = T, results = 'hide',  error=FALSE, warning=FALSE, message=FALSE}
open1 <- read_xlsx("open1.xlsx")
open1.1 <- read_xlsx("open1_1.xlsx")
open2 <- read_xlsx("open2.xlsx")
open2.1 <- read_xlsx("open2_1.xlsx")
open3 <- read_xlsx("open3.xlsx")
```

## Analysis of Open-Ended Survey Responses

```{r, error=FALSE, warning=FALSE, message=FALSE}
# Open-Ended Q1
open1 <- open1[-c(3),]
ggplot(open1, aes(x=Partisan_Disagreement, y=val,
    fill = factor(ifelse(Partisan_Disagreement=="Is a Concern", "Highlighted",
                         "Normal")))) +
    geom_bar(stat ="identity", show.legend = F, alpha=.6, width=.4) +
    scale_fill_manual(name = "", values=c("red3","skyblue")) +
    coord_flip() + xlab("Partisan Disagreement over War") + 
    ylab("Number of Responses (n = 168; DK responses omitted)") +
    ggtitle("Is Partisan Disagreement over War a Concern?") +
    theme_bw()

open1.1 <- open1.1[-c(4),] 
open1.1$no <- rep("", nrow(open1.1))
open1.1 %>%
  mutate(name = fct_relevel(Reason, "Others", "Damages Unity and Trust",
            "Unclear National Interest")) %>%
  ggplot( aes(fill=name, y=val, x=no)) + 
    geom_bar(position="fill", stat="identity", alpha=.6, width=.4) +
    coord_flip() + xlab("") + theme(axis.title.x=element_blank()) + 
    ylab("Portion of Responses (n = 77; DK responses omitted)") +
    scale_fill_manual(name = "", values=c("brown4", "orange3", "beige")) +
    ggtitle("Why Is Partisan Disagreement over War Troublesome?") + theme_bw()

# Open-Ended Q2
open2 <- open2[-c(3,4),]
ggplot(open2, aes(x=Bipartisan_Agreement, y=...2,
    fill = factor(ifelse(Bipartisan_Agreement=="Is Important", "Highlighted",
                         "Normal")))) +
    geom_bar(stat ="identity", show.legend = F, alpha=.6, width=.4) +
    scale_fill_manual(name = "", values=c("red3","skyblue")) +
    coord_flip() + xlab("Importance of Bipartisan Agreement over War") + 
    ylab("Number of Responses (n = 166; DK responses omitted)") +
    ggtitle("Is Bipartisan Agreement over War Important?") +
    theme_bw()

open2.1 <- open2.1[-c(4),]
open2.1$no <- rep("", nrow(open2.1))
open2.1 %>%
  mutate(name = fct_relevel(Reason, "Others", "Cohesion and Trust",
            "Clear National Interest")) %>%
  ggplot( aes(fill=name, y=...2, x=no)) + 
    geom_bar(position="fill", stat="identity", alpha=.6, width=.4) +
    coord_flip() + xlab("") + theme(axis.title.x=element_blank()) + 
    ylab("Portion of Responses (n = 97; DK responses omitted)") +
    scale_fill_manual(name = "", values=c("darkgreen","green4", "yellowgreen")) +
    ggtitle("Why Is Bipartisan Agreement over War Important?") + theme_bw()

# Open-Ended Q3
open3 <- open3[-c(4),]
open3$no <- rep("", nrow(open3))
open3 %>%
  mutate(name = fct_relevel(Will_to_Fight, "Others", "Soldier-to-Soldier Trust",
            "National Interest")) %>%
  ggplot( aes(fill=name, y=...2, x=no)) + 
    geom_bar(position="fill", stat="identity", alpha=.6, width=.4) +
    coord_flip() + xlab("") + theme(axis.title.x=element_blank()) + 
    ylab("Portion of Responses (n = 205; DK responses omitted)") +
    scale_fill_manual(name = "", values=c("skyblue4", "skyblue", "cyan2")) +
    ggtitle("What motivates soldiers to fight?") + theme_bw()
```